package com.jindi.appplan;

import com.jindi.appuser.common.EmptyUtil;
import com.jindi.appuser.common.PlanUtil;
import com.jindi.appuser.common.TimeUtils;
import org.aspectj.weaver.SignatureUtils;
import org.springframework.boot.autoconfigure.session.SessionProperties;
import redis.clients.jedis.Jedis;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * Created with IntelliJ IDEA.
 * User: duanj
 * Date: 2017-12-21
 * Time: 17:26
 * Description:
 */
public class Test {
    public static void main(String[] args) {
        /**
         * 抽奖系统
         *
         * 永久 5%，一天 15%  ，再来一次  30% ，谢谢参与 50%
         */

        int max = 100;
        int min = 0;
        int countYJ = 0;
        int countYT = 0;
        int countMor = 0;
        int countThink = 0;
        int num = 20;

        for (int i = 0; i < num; i++) {
            int a = (int) (Math.random() * (max - min)) + min ;
            System.out.println(a);
            if (a < 5) {
                countYJ++;
            }else if(a>=5 && a<20){
                countYT++;
            }
            else if(a>=20 && a<50){
                countMor++;
            } else if(a>=50){
                countThink++;
            }
        }
        System.out.println("抽奖"+num+"次，永久中奖次数"+countYJ+"，中奖率"+geh(countYJ, num)+"%");
        System.out.println("抽奖"+num+"次，一天中奖次数"+countYT+"，中奖率"+geh(countYT, num)+"%");
        System.out.println("抽奖"+num+"次，再来一次中奖次数"+countMor+"，中奖率"+geh(countMor, num)+"%");
        System.out.println("抽奖"+num+"次，谢谢参与中奖次数"+countThink+"，中奖率"+geh(countThink, num)+"%");
    }

    static String geh(int num1,int num2){

        // 创建一个数值格式化对象

        NumberFormat numberFormat = NumberFormat.getInstance();

        // 设置精确到小数点后2位

        numberFormat.setMaximumFractionDigits(2);

        String result = numberFormat.format((float) num1 / (float) num2 * 100);

       return  result;
    }


}
